/*
 * Copyright (C) 2009 Kristopher T Babic
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, see <http://www.gnu.org/licenses>.
 */

package edu.idp.client;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

/**
 *
 * @author Kristopher T Babic
 */
public class UpdateThread extends Thread {
    private transient Vector actionListeners = null;

    public UpdateThread() {
    }


    public void run() {
        System.out.println("update thread running");
        while (true) {

            try {
                Thread.sleep(300000);
            }
            catch (Exception e) {
            }

            processActionEvent(new ActionEvent(this, ActionEvent.ACTION_FIRST, "update"));
        }


    }

    public synchronized void addActionListener(ActionListener l) {
        if (l == null)
            return;
        if (actionListeners == null)
            actionListeners = new Vector();

        actionListeners.add(l);
    }

    public synchronized void removeActionListener(ActionListener l) {
        if (l == null || actionListeners == null || actionListeners.size() <= 0)
            return;

        actionListeners.remove(l);

    }

    protected void processActionEvent(ActionEvent e) {
//    System.out.println("fireing event");
        if (actionListeners != null) {
            for (int i = 0; i < actionListeners.size(); i++)
                ((ActionListener) actionListeners.elementAt(i)).actionPerformed(e);
        }
    }

} 